'use client'

import {useState} from 'react'
import type {ProColumns} from '@ant-design/pro-components'
import {ProTable} from '@ant-design/pro-components'
import {Button, message, Modal} from 'antd'
import {PlusOutlined} from '@ant-design/icons'

type SupplierItem = {
  id: string
  name: string
  code: string
  contact: string
  phone: string
  email: string
  address: string
  status: 'active' | 'inactive'
  createTime: string
  updateTime: string
}

export default function SuppliersPage() {
  const [createModalVisible, setCreateModalVisible] = useState(false)

  const columns: ProColumns<SupplierItem>[] = [
    {
      title: '供应商名称',
      dataIndex: 'name',
      width: 200,
    },
    {
      title: '供应商编码',
      dataIndex: 'code',
      width: 120,
      copyable: true,
    },
    {
      title: '联系人',
      dataIndex: 'contact',
      width: 120,
    },
    {
      title: '联系电话',
      dataIndex: 'phone',
      width: 120,
    },
    {
      title: '邮箱',
      dataIndex: 'email',
      width: 180,
    },
    {
      title: '地址',
      dataIndex: 'address',
      width: 300,
      ellipsis: true,
    },
    {
      title: '状态',
      dataIndex: 'status',
      width: 100,
      valueEnum: {
        active: { text: '启用', status: 'Success' },
        inactive: { text: '禁用', status: 'Error' },
      },
    },
    {
      title: '创建时间',
      dataIndex: 'createTime',
      width: 180,
      valueType: 'dateTime',
    },
    {
      title: '更新时间',
      dataIndex: 'updateTime',
      width: 180,
      valueType: 'dateTime',
    },
    {
      title: '操作',
      width: 180,
      key: 'option',
      valueType: 'option',
      render: (_, record) => [
        <a
          key="edit"
          onClick={() => {
            message.info('编辑功能开发中')
          }}
        >
          编辑
        </a>,
        <a
          key="delete"
          onClick={() => {
            Modal.confirm({
              title: '确认删除',
              content: '确定要删除这个供应商吗？',
              onOk: () => {
                message.success('删除成功')
              },
            })
          }}
        >
          删除
        </a>,
      ],
    },
  ]

  const mockData: SupplierItem[] = [
    {
      id: '1',
      name: '苹果公司',
      code: 'SUP001',
      contact: 'Tim Cook',
      phone: '13800138000',
      email: 'contact@apple.com',
      address: '美国加利福尼亚州库比蒂诺',
      status: 'active',
      createTime: '2024-03-01 10:00:00',
      updateTime: '2024-03-01 10:00:00',
    },
    {
      id: '2',
      name: '华为技术有限公司',
      code: 'SUP002',
      contact: '任正非',
      phone: '13800138001',
      email: 'contact@huawei.com',
      address: '中国广东省深圳市龙岗区坂田华为基地',
      status: 'active',
      createTime: '2024-03-01 11:00:00',
      updateTime: '2024-03-01 11:00:00',
    },
  ]

  return (
    <ProTable<SupplierItem>
      columns={columns}
      dataSource={mockData}
      rowKey="id"
      search={{
        labelWidth: 120,
      }}
      toolBarRender={() => [
        <Button
          key="button"
          icon={<PlusOutlined />}
          type="primary"
          onClick={() => setCreateModalVisible(true)}
        >
          新建
        </Button>,
      ]}
    />
  )
} 